package ${configs.packagePath}.exception;

import ${configs.packagePath}.common.R;
import ${configs.packagePath}.utils.RR;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <Description>
 * 全局异常处理器
 * @author Jun Lee
 * @version 1.0
 * @createDate ${date}
 */
@Slf4j
@ControllerAdvice
public class BaseExceptionHandler {

    @ResponseBody
    @ExceptionHandler(CustomException.class)
    public R CustomException(CustomException e){
        log.error(e.getMessage(),e);
        return RR.customize(e.getCode(),e.getMessage());
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public R Exception(Exception e){
        log.error(e.getMessage(),e);
        return RR.fail();
    }
}
